﻿@{
    Layout = null;
}
@model int?
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Edit</title>
    <script src="~/Content/angular/angular.js"></script>
</head>
<body>
    <div ng-app="MyApp">
        <div ng-controller="testC">
            <form>
                <div>
                    <span>按钮名称：</span>
                    <input type="text" ng-model="ButtonInfo.ButtonName" />
                </div>
                <div>
                    <span>默认Action名称：</span>
                    <input type="text" ng-model="ButtonInfo.DefaultActionName" />
                </div>
                <div>
                    <span>默认执行脚本：</span>
                    <input type="text" ng-model="ButtonInfo.DefaultExecution" />
                </div>
                <div>
                    <span>是否写入控制器名称：</span>
                    <select ng-model="ButtonInfo.IsWriteControllerName">
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
                <div>
                    <span>默认位置：</span>
                    <input type="radio" ng-model="ButtonInfo.DefaultPosition" value="0" />无
                    <input type="radio" ng-model="ButtonInfo.DefaultPosition" value="1" />顶部工具栏
                    <input type="radio" ng-model="ButtonInfo.DefaultPosition" value="2" />右键工具栏
                    <input type="radio" ng-model="ButtonInfo.DefaultPosition" value="3" />普通工具栏
                </div>
                <div>
                    <span>图标：</span>
                    <input type="text" ng-model="ButtonInfo.Icon" />
                </div>
                <div>
                    <input type="button" value="提交" ng-click="Save()" />
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript">
        var app = angular.module('MyApp', [], function () { console.log('started') });
        app.controller('testC', function ($scope, $http) {
            $scope.Load = function () {

                $http.get("/api/btnapi/@(Model.HasValue ? Model.Value : 0)").success(function (data, status) {
                    $scope.ButtonInfo = data;
                })
            };

            $scope.Save = function () {
                $http.post("/api/btnapi",
                    //{
                    //    ButtonName: $scope.ButtonInfo.ButtonName,
                    //    DefaultActionName: $scope.ButtonInfo.DefaultActionName,
                    //    DefaultExecution: $scope.ButtonInfo.DefaultExecution,
                    //    IsWriteControllerName: $scope.ButtonInfo.IsWriteControllerName,
                    //    DefaultPosition: $scope.ButtonInfo.DefaultPosition,
                    //    Icon: $scope.Icon
                    //}
                    JSON.stringify($scope.ButtonInfo)
                    ).success(function (objInvokeResult, status) {
                        alert(objInvokeResult.ResultMessage);
                        window.location.href = "/Button";
                    })
            };

            $scope.Load();
        });
    </script>
</body>
</html>
